/*
 * @Author: your name
 * @Date: 2021-12-08 14:54:28
 * @LastEditTime: 2021-12-08 15:08:47
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \12.8work\test_one\common.js
 */
const option=[{
    title:'请输入姓名',
    value:'',
    cb(chunk,next){
        this.value=chunk.toString().trim()
        if(this.value.length>=5){
            next()
        }else{
            process.stdout.write(this.title)
        }
    }
},{
    title:'请输入密码',
    value:'',
    cb(chunk,next){
        this.value=chunk.toString().trim()
        if(this.value.length>=5){
            next()
        }else{
            process.stdout.write(this.title)
        }
    }
},{
    title:'请输入邮箱',
    value:'',
    cb(chunk){
        this.value=chunk.toString().trim()
        if(this.value.length>=5){
            console.log(option)
            process.exit()
        }else{
            process.stdout.write(this.title)
        }
    }
}]

module.exports=(option)=>{
    let count=0
    function next(){
        count+=1,
        process.stdout.write(option[count].title)
    }
    process.stdin.on('data',chunk=>{
        if(count===0){
            option[0].cb(chunk,next)
        }else if(count===1){
            option[1].cb(chunk,next)
        }else if(count===2){
            option[2].cb(chunk)
        }
    })
}